<template>
  <div class="carousel-container">
    <el-carousel 
      :height="height"
      :autoplay="autoplay"
      :interval="interval"
      indicator-position="outside"
      arrow="hover"
      @change="handleSlideChange"
    >
      <el-carousel-item v-for="(item, index) in items" :key="index">
        <div 
          class="carousel-item"
          :style="{ backgroundImage: `url(${item.image})` }"
          @click="handleItemClick(item)"
        >
          <div class="carousel-overlay">
            <div class="carousel-content">
              <h2 v-if="item.title" class="carousel-title">{{ item.title }}</h2>
              <p v-if="item.subtitle" class="carousel-subtitle">{{ item.subtitle }}</p>
              <el-button 
                v-if="item.buttonText" 
                type="primary" 
                size="large"
                class="carousel-button btn-hover"
                @click.stop="handleButtonClick(item)"
              >
                {{ item.buttonText }}
              </el-button>
            </div>
          </div>
        </div>
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script>
export default {
  name: 'ImageCarousel',
  props: {
    items: {
      type: Array,
      required: true,
      default: () => []
    },
    height: {
      type: String,
      default: '400px'
    },
    autoplay: {
      type: Boolean,
      default: true
    },
    interval: {
      type: Number,
      default: 4000
    }
  },
  emits: ['slide-change', 'item-click', 'button-click'],
  setup(props, { emit }) {
    const handleSlideChange = (index) => {
      emit('slide-change', index)
    }
    
    const handleItemClick = (item) => {
      emit('item-click', item)
    }
    
    const handleButtonClick = (item) => {
      emit('button-click', item)
    }
    
    return {
      handleSlideChange,
      handleItemClick,
      handleButtonClick
    }
  }
}
</script>

<style scoped>
.carousel-container {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.carousel-item {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: relative;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.carousel-item:hover {
  transform: scale(1.02);
}

.carousel-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    45deg,
    rgba(0, 0, 0, 0.4) 0%,
    rgba(0, 0, 0, 0.2) 50%,
    rgba(0, 0, 0, 0.1) 100%
  );
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel-content {
  text-align: center;
  color: white;
  max-width: 600px;
  padding: 20px;
}

.carousel-title {
  font-size: 2.5rem;
  font-weight: bold;
  margin-bottom: 1rem;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
  animation: fadeInUp 1s ease;
}

.carousel-subtitle {
  font-size: 1.2rem;
  margin-bottom: 2rem;
  opacity: 0.9;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
  animation: fadeInUp 1s ease 0.2s both;
}

.carousel-button {
  animation: fadeInUp 1s ease 0.4s both;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .carousel-title {
    font-size: 2rem;
  }
  
  .carousel-subtitle {
    font-size: 1rem;
    margin-bottom: 1.5rem;
  }
  
  .carousel-content {
    padding: 15px;
  }
}

@media (max-width: 480px) {
  .carousel-title {
    font-size: 1.5rem;
  }
  
  .carousel-subtitle {
    font-size: 0.9rem;
  }
}

/* 自定义轮播图指示器样式 */
:deep(.el-carousel__indicators) {
  margin-bottom: -10px;
}

:deep(.el-carousel__indicator) {
  padding: 8px 4px;
}

:deep(.el-carousel__button) {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.5);
  border: 2px solid transparent;
  transition: all 0.3s ease;
}

:deep(.el-carousel__indicator.is-active .el-carousel__button) {
  background-color: #FF8C00;
  border-color: white;
  transform: scale(1.2);
}

/* 自定义箭头样式 */
:deep(.el-carousel__arrow) {
  background-color: rgba(255, 255, 255, 0.8);
  border-radius: 50%;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

:deep(.el-carousel__arrow:hover) {
  background-color: rgba(255, 255, 255, 0.95);
  transform: scale(1.1);
}

:deep(.el-carousel__arrow i) {
  color: #FF8C00;
  font-size: 20px;
}
</style>
